package org.xbzheng.sc.core.aspect;

import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Created by Administrator on 2016/7/22.
 */
public class ChooseDataSource extends AbstractRoutingDataSource {
    public static Map<String, Set<String>> METHOD_TYPE = new HashMap<String, Set<String>>(2);
    @Override
    protected Object determineCurrentLookupKey() {
        return HandlerDataSource.getDataSource();
    }

    public void setMethodType(final Map<String, String> map){
        for(final String key : map.keySet()){
            final Set<String> methodNameSet = new HashSet<String>();
            final String methodNameStr = map.get(key);
            if(StringUtils.isNoneBlank(methodNameStr)){
                final String[] methodNameArr = methodNameStr.split(",");
                for(String methodName: methodNameArr){
                    if(StringUtils.isNoneBlank()){
                        methodNameSet.add(methodName);
                    }
                }
            }
            METHOD_TYPE.put(key, methodNameSet);
        }
    }
}
